/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.                       */
/*                                                                            */
/*  NAME      = CUPS_comm.h                                                   */
/*  NOTE      =                                                               */
/*  DATE      = 2015/03/19 by zhengxd                                         */
/******************************************************************************/
#ifndef _CUPS_COMM_H_
#define _CUPS_COMM_H_

/* 共通函数 */

#include "cups_core.h"

#define CUPS_REPORT_KEY_REQ              APM_REPORT_KEY_REQ".cups"
#define CUPS_REPORT_KEY_RESP             APM_REPORT_KEY_RESP".cups"
#define CUPS_REPORT_KEY_REQ_MSG_TP       CUPS_REPORT_KEY_REQ".message_type"
#define CUPS_REPORT_KEY_RESP_MSG_TP      CUPS_REPORT_KEY_RESP".message_type"
#define CUPS_REPORT_KEY_REQ_TRANS        CUPS_REPORT_KEY_REQ".trans_info"
#define CUPS_REPORT_KEY_REQ_DEST_ID      CUPS_REPORT_KEY_REQ".dest_id"
#define CUPS_REPORT_KEY_REQ_SRC_ID       CUPS_REPORT_KEY_REQ".src_id"
#define CUPS_REPORT_KEY_RESP_MSG_TP      CUPS_REPORT_KEY_RESP".message_type"
#define CUPS_REPORT_KEY_RESP_TRANS       CUPS_REPORT_KEY_RESP".trans_info"
#define CUPS_REPORT_KEY_RESP_DEST_ID     CUPS_REPORT_KEY_RESP".dest_id"
#define CUPS_REPORT_KEY_RESP_SRC_ID      CUPS_REPORT_KEY_RESP".src_id"

/*
 *  域信息
*/
typedef struct __st_cups_field_info {

    unsigned int ui_field_index;
    char *p_field_value;
} cups_field_info;

char* cups_ret_value(unsigned int ui_index);

char* cups_error_msg(unsigned int ui_rej_code);

void cups_free(char **pp_value);

int cups_parse_head(Frbyte_Packet *p_st_data
                    , char *p_dest_id
                    , char *p_src_id
                    , char *p_trans_info
                    , char *p_msg_type
                    , char *p_bitmap
                    , unsigned int *p_bitmap_len
                    , unsigned int *p_rej_code);

void cups_field_free(cups_field_info **pp_st_field);

void cups_node_free(Frlist_node *p_st_node);

void cups_dbg(void);

int cups_str2len(char *p_len, unsigned int ui_len ,unsigned int *p_ui_len);

int cups_get_len(Frbyte_Packet *p_st_data
                  , unsigned int ui_len
                  , unsigned int *p_ui_len);

int cups_get_str(Frbyte_Packet *p_st_data
                  , unsigned int ui_len
                  , char **pp_value);

int cups_get_binary(Frbyte_Packet *p_st_data
                     , unsigned int ui_len
                     , char **pp_value);

int cups_get_datetime(Frbyte_Packet *p_st_data
                      , char **pp_output);

int cups_get_time(Frbyte_Packet *p_st_data, char **pp_output);

int cups_get_date(Frbyte_Packet *p_st_data, char **pp_output);

int cups_create_llvar(Frbyte_Packet *p_st_data
                       , unsigned int ui_field_idx
                       , Frlist_header *p_st_fields);

int cups_create_lllvar(Frbyte_Packet *p_st_data
                       , unsigned int ui_field_idx
                       , Frlist_header *p_st_fields);

int cups_create_bytes(Frbyte_Packet *p_st_data
                       , unsigned int ui_field_idx
                       , unsigned int ui_len
                       , Frlist_header *p_st_fields);

int cups_create_binary(Frbyte_Packet *p_st_data
                       , unsigned int ui_field_idx
                       , unsigned int ui_len
                       , Frlist_header *p_st_fields);

int cups_create_datetime(Frbyte_Packet *p_st_data
                          , unsigned int ui_field_idx
                          , Frlist_header *p_st_fields);

int cups_create_time(Frbyte_Packet *p_st_data
                      , unsigned int ui_field_idx
                      , Frlist_header *p_st_fields);

int cups_create_date(Frbyte_Packet *p_st_data
                      , unsigned int ui_field_idx
                      , Frlist_header *p_st_fields);

int cups_create_rate(Frbyte_Packet *p_st_data
                       , unsigned int ui_field_idx
                       , unsigned int ui_len
                       , Frlist_header *p_st_fields);

unsigned long cups_get_interval_time(struct timeval *p_st_start_time
                                     , struct timeval *p_st_end_time);

void cups_destroy_request(L7_req_cups **pp_st_req);

void cups_destroy_response(L7_resp_cups **pp_st_resp);

void cups_init_fragment(L7_fragment_cups *p_st_fragment);

void cups_destroy_fragment(L7_fragment_cups **pp_st_fragment);

int cups_get_currency(char **pp_currency, unsigned int ui_digits);

int cups_get_currency2(char **pp_currency, unsigned int ui_digits);

void cpus_get_digits(unsigned int ui_currency_type, unsigned int *p_ui_digits);

int cups_get_type_name(char *p_type_code, char **pp_type_name);

int cups_get_channel(char *p_reserved, char **pp_channel);

#endif
